package org.example.controller;


import com.alipay.remoting.exception.CodecException;
import org.example.command.OrderCmd;
import org.example.order.CmdType;
import org.example.order.OrderDirection;
import org.example.server.EngineServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedList;
import java.util.List;

@RestController
public class TestController {

    @Autowired
    EngineServer engineServer;

    @GetMapping("/send_msg_to_engine/{direction}")
    public String sendMsgToEngine(@PathVariable OrderDirection direction) throws CodecException {
        List<OrderCmd> cmds = new LinkedList<>();
        OrderCmd orderCmd = new OrderCmd();
        orderCmd.setCode(00001);
        orderCmd.setPrice(10000);
        orderCmd.setDirection(direction);
        orderCmd.setVolumn(100);
        orderCmd.setTimestamp(System.currentTimeMillis());
        orderCmd.setType(CmdType.NEW_ORDER);
        cmds.add(orderCmd);
        engineServer.send(cmds);
        return cmds.toString();
    }
}
